package com.qb.hotelTV.network;

import android.util.Log;

import com.qb.hotelTV.constants.AppConstants;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 请求头拦截器
 * 统一处理HTTP请求头，添加通用的头部信息
 */
public class HeaderInterceptor implements Interceptor {
    private static final String TAG = "HeaderInterceptor";
    
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        
        // 构建新的请求，添加通用头部
        Request.Builder requestBuilder = originalRequest.newBuilder()
                .addHeader("Content-Type", AppConstants.ApiConfig.CONTENT_TYPE_JSON)
                .addHeader("Accept", AppConstants.ApiConfig.CONTENT_TYPE_JSON)
                .addHeader("Accept-Charset", AppConstants.ApiConfig.CHARSET_UTF8)
                .addHeader("User-Agent", "HotelTV-Android/1.0")
                .addHeader("Connection", "keep-alive")
                .addHeader("Cache-Control", "no-cache");
        
        Request newRequest = requestBuilder.build();
        
        Log.d(TAG, "添加通用请求头: " + newRequest.url());
        
        return chain.proceed(newRequest);
    }
} 